
<?php
	$whmcs_path = "whmcs";
	$path = "http://" . $_SERVER['SERVER_NAME'] . "/whmcs/modules/admin/server_log/";
	$rootDoc = $_SERVER{'DOCUMENT_ROOT'};
	include_once $rootDoc."whmcs/modules/admin/server_log/utilities/functions.php";	
	
?>

<script src="<?php echo $path; ?>js/jquery-1.6.js" type="text/javascript" language="javascript"></script>
<script src="<?php echo $path; ?>js/jquery-ui-1.8.12.custom.min.js" type="text/javascript" language="javascript"></script>
<link href="templates/original/style.css" rel="stylesheet" type="text/css" />
<link href='<?php echo $path; ?>css/style.css' rel='stylesheet' type='text/css'>
<link href='<?php echo $path; ?>css/ui-lightness/jquery-ui-1.8.12.custom.css' rel='stylesheet' type='text/css'>

<div>
	<?php				
		if(isset($_REQUEST['btnSubmitServerVPS'])){			//Add new VPS
			if(!isEixtedLog($_REQUEST['txtVPSIP'])){
				$query = "INSERT INTO mod_serverlog(ip, domain, createdby) 
							VALUES('".$_REQUEST['txtVPSIP']."','".$_REQUEST['txtVPSHost']."','".$_SESSION['adminid']."')";
				$inserted = mysql_query($query);
				
				if(!$inserted)
					echo "<div class='infobox'>Error Insert</div>";
				else
					echo "<div class='infobox'>Create Log Successful. You can add Server/VPS log now by click to 'Add Log' link</div>";
				
			}else
				echo "<div class='infobox'>Server log existed!</div>";			
		}
		
		//Delete Server log
		if(isset($_GET['act']) && $_GET['act']=='del'){
			$query = "DELETE FROM mod_serverlog WHERE ip = '".mysql_real_escape_string($_REQUEST['serverID'])."'";			
			mysql_query($query);
			$delete = mysql_affected_rows();
			
			if($delete)
				echo "<div class='infobox'>Delete Log Successful.</div>";
			
		}
		
		//Script select server information by hosing ID
		$query = "SELECT tag, name FROM mod_servermanager WHERE id = ".mysql_real_escape_string($_REQUEST['hostid']);
		$rs = mysql_query($query);	
		$row = mysql_fetch_array($rs);
		$tag = $row['tag'];		
	?>

	<form method="POST" action="<?php echo $_SERVER['PHP_SELF']."?module=server_log" ?>" onSubmit="return validateIPAndHostingInfor()">	
		<fieldset style="border: 1px solid #8FBCE9">
			<!--<table border="0" cellpadding="2" cellspacing="2" width='30%'>	
				<tr>
						server combobox	
					<td><?php //echo getAllServer(); ?></td>
					<td align="center">
						<input type="submit" name="sbmServerLog" id="sbmServerLog" value="Add log" />
					</td>					
				</tr>
			</table>-->
			
			<table border="0" cellpadding="2" cellspacing="2" width='30%'>	
				<tr>
					<td>IP:</td>
					<td>
						<input type="text" name="txtVPSIP" size="30" onKeyPress="enableButton()" />
					</td>				
					<td>Host:</td>
					<td>
						<input type="text" name="txtVPSHost" size="30" onfocus="enableButton()"/>
					</td>
					<td>
						<input type="submit" name="btnSubmitServerVPS" id="btnSubmitServerVPS" value="Add New  (SERVER / VPS)" />
					</td>
				</tr>
			</table>
		</fieldset>
	</form>
</div>
<br/>
<!-- 	View server logs Added		-->
<?php  echo getServerLogModified();	?>

<br/><br/>

<script src="editor/tiny_mce.js"></script>
<script type="text/javascript">
		 tinyMCE.init({
		 mode : "textareas",
		 theme : "advanced",
		 convert_urls : false,
		 relative_urls : false,
		 plugins : "style,table,advhr,advimage,advlink,iespell,inlinepopups,insertdatetime,media,searchreplace,contextmenu,paste,directionality,fullscreen,visualchars,xhtmlxtras",
		 theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
		 theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		 theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,fullscreen",
		 theme_advanced_toolbar_location : "top",
		 theme_advanced_toolbar_align : "left",
		 theme_advanced_statusbar_location : "bottom",
		 theme_advanced_resizing : true
});
	function toggleEditor(id) {
		 if (!tinyMCE.get(id))
		 tinyMCE.execCommand('mceAddControl', false, id);
		 else
		 tinyMCE.execCommand('mceRemoveControl', false, id);
	} 	
</script>


	<form action="<?= $path; ?>addServerLogCommentAction.php" method="post">
	<a name="log"></a>
		<div id="comment_wrapper">			
			<?php			
				$currentFocusIP = isset($_REQUEST['txtVPSIP'])?$_REQUEST['txtVPSIP']:$_REQUEST['serverID'];
				if(isLogged($currentFocusIP)){
					echo "<div id='IPInfo' style='margin-bottom: 10px; color:#000066'>Adding logs for IP: ".whichServerIsAddingLog($currentFocusIP)."</div>";
				}else
					echo "<div id='IPInfo' style='margin-bottom: 10px; color:#000066'>Please Select Server/VPS In Above To Leave Comments</div>";
			?>
			
				<?php fetchServerLogByTable($currentFocusIP); ?>
			
			
			<div>
				<input type="hidden" name="txtUser" value="<?php echo $user; ?>" />
				<input type="hidden" name="txtID" value="<?php echo $currentFocusIP; ?>" />		
				<br/>		
				<br/>
				<a name="log"></a>		
				<center>
					
					<textarea id="myarea1" class="txtComments" name="txtComments" cols="100" rows="20" ></textarea> 
							
				</center>
				<br/>
				<center><input type="submit" name="btnSubmit" id="savecomment" class="button" value="Save Comment" /></center>
			</div>	
		</div>	
	</form>

<script src="<?php echo $path; ?>js/functions.js" type="text/javascript" language="javascript"></script>
<?php
	if(isset($_REQUEST['serverID'])){
?>
		<script>
			$('#comment_wrapper').show();
		</script>
<?php
	}
?>

